package com.entrogy.service.impl;

import com.entrogy.bean.BorrowBookEntity;
import com.entrogy.bean.UserEntity;
import com.entrogy.dao.BorrowBookMapper;
import com.entrogy.dao.UserMapper;
import com.entrogy.service.BorrowBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**  图书借阅service 接口实现类
 * @Author 许红松
 * @date 2019/6/17 0017 上午 10:50
 */
@Service("borrowBookService")
public class BorrowBookServiceImpl implements BorrowBookService {

    @Autowired
    private BorrowBookMapper borrowBookMapper;//图书借阅dao接口
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<BorrowBookEntity> getBorrowBookList(Map<String, Object> map) {
        if (!map.containsKey("school_code")){
            if (map.containsKey("dingdingId")){
                UserEntity userEntity=userMapper.getUserById(map.get("dingdingId").toString());
                if (userEntity!=null){
                    map.put("school_code",userEntity.getSchoolCode());
                    map.put("UserId",userEntity.getId());
                }
            }

        }
        return borrowBookMapper.getBorrowBookList(map);
    }

    @Override
    public BorrowBookEntity getBorrowBookByid(String id) {
        return borrowBookMapper.getBorrowBookByid(id);
    }

}
